package com.example.mybatisplus.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.model.vo.StatVO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.WhitelistSettingService;
import com.example.mybatisplus.model.domain.WhitelistSetting;

import java.util.ArrayList;
import java.util.List;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2024-12-12
 * @version v1.0
 */
@Controller
@RequestMapping("/api/whitelistSetting")
public class WhitelistSettingController {

    private final Logger logger = LoggerFactory.getLogger( WhitelistSettingController.class );

    @Autowired
    private WhitelistSettingService whitelistSettingService;

    @PostMapping("/login")
    @ResponseBody
    public JsonResponse login(@RequestBody WhitelistSetting whitelistSetting){
      WhitelistSetting loginUser = whitelistSettingService.login(whitelistSetting);
      return JsonResponse.success(loginUser);
    }

    @GetMapping("/pageList")
    @ResponseBody
    public JsonResponse pageList(PageDTO pageDTO,WhitelistSetting whitelistSetting){
        Page<WhitelistSetting> page = whitelistSettingService.pageList(pageDTO,whitelistSetting);
        return JsonResponse.success(page);
    }

    @PostMapping("/save")
    @ResponseBody
    public JsonResponse save(@RequestBody WhitelistSetting whitelistSetting){
        boolean save = whitelistSettingService.save(whitelistSetting);
        return JsonResponse.success(save);
    }

    //
    // do(entity)
    // vo 视图层对象
    // dto 数据传输层对象

    @GetMapping("/stat")
    @ResponseBody
    public JsonResponse stat(){
        List<StatVO> list = whitelistSettingService.stat();
        return JsonResponse.success(list);
    }
}

